package com.example.demo.sample.dao.impl;

import com.example.demo.sample.dao.IUserDao;
import com.example.demo.sample.model.UserDO;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangqidzq on 2017/9/10.
 */
@Repository
public class UserDaoImpl implements IUserDao {

    //简单的模拟数据库
    List<UserDO> userDOList = new ArrayList<>();

    @Override
    public void add(UserDO userDO) throws Exception {
        this.userDOList.add(userDO);
    }

    @Override
    public void deleteById(Long userId) {
        for (UserDO userDO : userDOList) {
            if (userDO.getId().equals(userId)) {
                userDOList.remove(userDO);
                break;
            }
        }
    }

    @Override
    public void updateById(UserDO userDO) {


    }

    @Override
    public UserDO selectByUserName(String userName) {
        for (UserDO userDO : userDOList) {
            if (userDO.getUserName().equals(userName)) {
                return userDO;
            }
        }
        return null;
    }
}
